/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import IBO.ITechnicien;
import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.catalina.Session;

/**
 *
 * @author Administrateur
 */
public class Intervention extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        PrintWriter page = response.getWriter();
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
        doPost(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
   
        RequestDispatcher disp = this.getServletContext().getRequestDispatcher("/index.jsp");
        //récupération id intervention
        
        String identifiant  = (String) request.getParameter("identifiant");
        System.out.println("debug:"+ identifiant);
        int id = Integer.parseInt(identifiant);
        ITechnicien tech = (ITechnicien) request.getSession().getAttribute("technicien");
        for(int i=0; i<tech.getListeIInterventionsToday().size();i++){
            if(id==tech.getListeIInterventionsToday().get(i).getIdIntervention()){
                request.getSession().setAttribute("intervention", tech.getListeIInterventionsToday().get(i));
            }
        }
        this.gotoPage("/InterventionInfo.jsp", request, response);
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    @Override
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>


    private void gotoPage(String adress, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher dispatcher =
		getServletContext().getRequestDispatcher(adress);
		dispatcher.forward(request,response);
    }
}
